import axios from "axios";

const service = axios.create({
    baseURL:"http://localhost:8080/",
    headers: {'Content-Type': 'application/json'},
    timeout:500000
  });
  service.interceptors.request.use(
    config => {
//         console.log(config.url)
//         console.log(localStorage.getItem('authToken'))
//     // 给每个请求都加上token请求头 || config.url === '/checkLogin' && (localStorage.getItem('token') != null)
//     if (config.url !== '/userlogin') {
//         if (localStorage.getItem('authToken')) {
//         //   config.headers.token = localStorage.getItem('token');

// // 在请求头设置AUTH_TOKEN的值
// // 后端会获取这个值
//           config.headers.AUTH_TOKEN =localStorage.getItem('authToken');
//           console.log(config.headers.AUTH_TOKEN)
//         } else {
//           this.$router.push('/');
//         }
//       }
      return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

  export default service;